<template>
  <Form ref="formInline" :model="formInline" :rules="ruleInline" inline>
    <FormItem prop="user">
      <Input type="text" v-model="formInline.name" placeholder="Username">
      <Icon type="ios-person-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem prop="password">
      <Input type="password" v-model="formInline.psw" placeholder="Password">
      <Icon type="ios-locked-outline" slot="prepend"></Icon>
      </Input>
    </FormItem>
    <FormItem>
      <Button type="primary" @click="handleSubmit()">登录</Button>
    </FormItem>
     <Button type="primary" @click="test()">1111</Button>
  </Form>
</template>
<script>
import Cookies from "js-cookie";
import { login } from "@/api/login";
export default {
  data() {
    return {
      formInline: {
        name: "",
        psw: ""
      },
      ruleInline: {
        user: [{ required: true, message: "请填写用户名", trigger: "blur" }],
        password: [
          { required: true, message: "请填写密码", trigger: "blur" },
          { type: "string", min: 6, message: "密码长度不能小于6位", trigger: "blur" }
        ]
      }
    };
  },
  methods: {
    handleSubmit() {
      login({
        name:this.formInline.name,
        psw:this.formInline.psw
      }).then(res => {
        const result = res.data;
        console.log(res)
        if (result.success) {
           Cookies.set("user", this.formInline.name);
              Cookies.set("password", this.formInline.psw);
                Cookies.set('access', 1);
            this.$router.push({name: 'home'});
        }else {
              this.$Message.error("表单验证失败!");
            }
      });
    },
    test(){
      this.$router.push({name: 'home'});
    }
  }
};
</script>
<style>

</style>
